package com.st.mall.member.controller;

import java.util.Arrays;
import java.util.Map;

import com.st.common.dubboProvider.DemoService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.st.mall.member.entity.MemberEntity;
import com.st.mall.member.service.MemberService;
import com.st.common.utils.PageUtils;
import com.st.common.utils.R;


/**
 * 会员
 *
 * @author fg
 * @email f@163.com
 * @date 2023-02-26 20:24:58
 */
@RestController
@RequestMapping("member/member")
public class MemberController {
    @Autowired
    private MemberService memberService;
    //    @Autowired
//    private CouponFeignService couponFeignService;
//
//    /**
//     * 用openFeign调用coupon的远程服务
//     *
//     * */
//    @RequestMapping("/getCut")
//    public R getCuts() {
//        MemberEntity me = new MemberEntity();
//        me.setNickname("刘强东");
//        me.setCity("夏威夷");
//        //Feign远程调用
//        R coupons = couponFeignService.coupons();
//
//        return R.ok().put("member",me).put("cut",coupons.get("cut"));
//    }
    //dumbo提供的Reference注解，用于调用远程服务
    @DubboReference(check = false)
    private DemoService categoryService;

    /**
     * 用dubbo调用product的远程服务
     *
     */
    @GetMapping("/dubbo/getTree")
    public R getTree() {
        return R.ok().put("data", categoryService.returnTree());
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = memberService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id) {
        MemberEntity member = memberService.getById(id);

        return R.ok().put("member", member);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody MemberEntity member) {
        memberService.save(member);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody MemberEntity member) {
        memberService.updateById(member);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids) {
        memberService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
